function! ollama#setup#GetModels(url)
    let g:ollama_models = []
    py3 <<EOF
try:
    import requests
    import vim
    url = f"{vim.eval('a:url')}/api/tags"
    response = requests.get(url)
    if response.status_code == 200:
        data = response.json() # { "response" :  }  # Assuming the response is JSON
        for m in data["models"]:
            name = m["name"]
            model = { "name" : name, "model" : m["model"], "modified_at" : m["modified_at"] }
            model["size"] = f"{m['size']}"
            model["digest"] = m["digest"]
            model["details"] = m["details"]
            vim.command("call add(g:ollama_models, py3eval('name'))")
            # vim.vars["g:ollama_models"] = data
finally:
    pass
EOF
    return g:ollama_models
endfunction

echo ollama#setup#GetModels(g:ollama_host)
